#include <iostream>
#include <iomanip>

using namespace std;

double l[10000];

double turn(double a,int type);

int main(){
    int n;
    cin >> n;
    double a;
    int type;
    for(int i = 0; i< n; i++){
        cin >> a >> type;
        l[i] = turn(a,type);
    }
    for(int i = 0; i< n; i++){
        cout << fixed << setprecision(3) << l[i] << endl;
    }
}


double turn(double a, int type){
    if(type==1){
        return 9/5.0*a+32;
    }
    if(type==2){
        return (a-32)*5/9.0;
    }
}